Hello, i need help to write Regexp , i have this expression "ref- 12" i want to find all objects with this expression
Regexp re = regexp2 "/[r][e][f][-] +([0-9]+)/" I get error for my code can anyone help please ?
Regards, Neven Control17 - Mon Nov 06 04:29:40 EST 2017 |
Re: Regexp Hi Neven,
You don't need the / at the beginning and the end of the regexp. In other languages, like perl or sed, regular expressions are enclosed in //, not in ""; in DXL, they are only enclosed in "". I think that in no language you need both, "" and //. So, Regexp re = regexp2 "[r][e][f][-] +([0-9]+)" should work. By the way, if you are only looking for "ref- " and not for REF-, Ref-, reF- etc., you can write your regexp simply as Regexp re = regexp2 "ref- +([0-9]+)" If "REF- 12" shall also match, you would do the trick with Regexp re = regexp2 "[rR][eE][fF]- +([0-9]+)"
But: you say that you get errors for your code. The regular expression that you wrote will not match against "ref- 12", but otherwise, it is a valid regular expression, so an error should not occur from this code..
Regards, |